package com.miaowang.salad.adapter;

import java.util.List;

import prj.carmap.mobile.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.miaowang.salad.data.ServiceListData;

/**
 * 我的服务列表adapter
 */
public class MyServiceAdapter extends BaseAdapter {

	private Context context;
	List<ServiceListData> serviceDataList;

	public MyServiceAdapter(Context context,
			List<ServiceListData> serviceDataList) {
		this.context = context;
		this.serviceDataList = serviceDataList;
	}

	@Override
	public int getCount() {
		return serviceDataList.size();
	}

	@Override
	public Object getItem(int position) {
		return serviceDataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.listview_item_service, null);
			holder = new ViewHolder();
			holder.tv_service_date = (TextView) convertView
					.findViewById(R.id.tv_service_date);
			holder.tv_service_type = (TextView) convertView
					.findViewById(R.id.tv_service_type);
			holder.tv_service_state = (TextView) convertView
					.findViewById(R.id.tv_service_state);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		ServiceListData serviceListData = serviceDataList.get(position);
		holder.tv_service_type.setText(serviceListData.getService_type());
		holder.tv_service_state.setText(serviceListData.getStatus());
		holder.tv_service_date.setText(serviceListData.getCreated_at());
		
		return convertView;
	}

	class ViewHolder {
		TextView tv_service_type;
		TextView tv_service_state;
		TextView tv_service_date;
	}

}
